package com.hxs.hxsserver.utils;

import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class PasswordUtils {


    private static final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

    /**
     * 校验密码
     * @param password 明文密码
     * @param userPassword 加密后密码
     * @return boolean
     */
    public static boolean passwordVerify(String password, String userPassword) {
        return BCrypt.checkpw(password, userPassword);
    }


    /**
     * Encrypts the password using BCrypt.
     *
     * @param password the plain text password to encrypt
     * @return the encrypted password as a string
     */
    public static String passwordEncrypt(String password) {
        return passwordEncoder.encode(password);
    }

}
